#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
#include<string.h>
typedef struct dancer
{
	char sex;
	char name[30];
}dan;
typedef struct loop_queue
{
	dan* d;
	int f;
	int r;
}lop;
#define SIZE 10
lop* queueinit()
{
	lop* pq = (lop*)malloc(sizeof(lop));
	if (pq == NULL)
	{
		printf("malloc fail");
		return NULL;
	}
	pq->d = (dan*)malloc(sizeof(dan) * SIZE);
	if (pq->d == NULL)
	{
		free(pq);
		return NULL;
	}
	pq->f = pq->r = 0;
	return pq;
}
bool is_empty(lop* pq)
{
	if (pq->f == pq->r)
		return true;
	else
		return false;
}
bool is_full(lop* pq)
{
	if (pq->f == ((pq->r + 1) % SIZE))
		return true;
	else
		return false;
}
bool enqueue(lop* pq, dan d)
{
	if (is_full(pq))
		return false;
	pq->d[pq->r] = d;
	pq->r = (pq->r + 1) % SIZE;
	return true;
}
bool outqueue(lop* pq, dan* d)
{
	if (is_empty(pq))
		return false;
	*d = pq->d[pq->f];
	pq->f = (pq->f + 1) % SIZE;
	return true;
}
bool get_head(lop* pq, dan* d)
{
	if (is_empty(pq))
		return false;
	*d = pq->d[pq->f];
	return true;
}
void match(dan* dancer, int num)
{
	lop* mqq = queueinit();
	lop* fqq = queueinit();
	dan d;
	int i = 0;
	for (i = 0; i < num; i++)
	{
		d = dancer[i];
		if (d.sex == 'f')
		{
			enqueue(fqq, d);
		}
		else
		{
			enqueue(mqq, d);
		}
	}
	while (!is_empty(fqq) && !is_empty(mqq))
	{
		outqueue(fqq, &d);
		printf("%s ", d.name);
		outqueue(mqq, &d);
		printf("%s\n", d.name);
	}
	if (!is_empty(fqq))
	{
		get_head(fqq, &d);
		printf("%s\n", d.name);
	}
	if (!is_empty(mqq))
	{
		get_head(mqq, &d);
		printf("%s\n", d.name);
	}
}
int main()
{
	dan dancer[5];
	int i = 0;
	for (i = 0; i < 5; i++)
	{
		printf("this is di %d ge\n", i);
		scanf("%s %c", &dancer[i].name, &(dancer[i].sex));
		getchar();
	}
	match(dancer, 5);
	return 0;
}